package com.xyc.servlet;

import com.xyc.mapper.OrderMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delOrder")
public class DelServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("del....");

        req.setCharacterEncoding("utf-8");

        int id = Integer.parseInt(req.getParameter("id_del"));
        System.out.println("id_del:"+id);

        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        OrderMapper orderMapper = ctx.getBean("orderMapper", OrderMapper.class);
        orderMapper.del(id);

        resp.sendRedirect("buycar.jsp");
    }
}
